﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Net.Mail;
using WWF.Contracts;
using System.Web.Configuration;

namespace WWF.Activities
{

    public sealed class NotifyInterviewer : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<ApplicationRequest> ApplicationRequest { get; set; }
        public InArgument<ApplicationResponse> ApplicationResponse { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {

            string baseURI = WebConfigurationManager.AppSettings["BaseURI"];

            if (string.IsNullOrEmpty(baseURI))
                throw new InvalidOperationException("No baseURI appSetting found in web.config");

            // Obtain the runtime value of the Text input argument
            ApplicationRequest applicationRequest = context.GetValue(ApplicationRequest);
            ApplicationResponse applicationResponse = context.GetValue(ApplicationResponse);
            string mailText = string.Format(Resources.InterviewNotificationMailTemplate,applicationRequest.ApplicantName, applicationResponse.ApplicationID, baseURI);


            SmtpClient smtpClient = new SmtpClient();
            MailMessage msg = new MailMessage("application@iss.nus.edu.sg", "interviewee@iss.nus.edu.sg", string.Format(Resources.InterviewNotificationMailSubject, applicationRequest.ApplicantName), mailText);
            msg.IsBodyHtml = true;
            smtpClient.Send(msg);
        }
    }
}
